package demo1;

import java.awt.*;
import java.util.*;
import java.util.List;

public class Solution {

    public void duplicateZeros(int[] arr) {
        //找到最后一个复写的位置
        int cur1 = 0;
        int cur2 = 0;
        while (cur2 < arr.length) {
            if (arr[cur1] != 0) {
                cur2++;
            } else {
                cur2 += 2;
            }
            cur1++;
        }
        cur1 = cur1 - 1;
        if (cur1 < 0) return;
        if (arr[cur1] == 0) {
            cur2 -= 2;
            cur1--;
        } else {
            cur2 -= 1;
            cur1--;
        }
        while (cur1 >= 0) {
            if (arr[cur1] == 0) {
                arr[cur2] = 0;
                cur2--;
                if (cur2 < 0) break;
                arr[cur2--] = 0;
            } else {
                arr[cur2] = arr[cur1];
                cur2--;
            }
            cur1--;
        }
    }

    public int maxArea(int[] height) {
        int max = 0;
        int start = 0;
        int end = height.length - 1;
        int area = 0;
        while ((start < end)) {
            if (height[start] < height[end]) {
                area = height[start] * (end - start);
                if (area > max) {
                    max = area;
                }
                start++;
            } else {
                area = height[end] * (end - start);
                if (area > max) {
                    max = area;
                }
                end--;
            }
        }
        return max;
    }

    public boolean isHappy(int n) {
        int fast = function(n);
        fast = function(fast);
        int slow = n;
        while (fast != slow) {
            slow = function(slow);
            fast = function(fast);
            fast = function(fast);
        }
        if (fast != 1) return false;
        return true;
    }

    public int function(int n) {
        int sum = 0;
        while (n > 0) {
            sum += (int) Math.pow(n % 10, 2);
            n /= 10;
        }
        return sum;
    }

    public static void main2(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.triangleNumber2(new int[]{2, 2, 3, 4}));
    }

    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        if (nums.length < 3) return 0;
        //用于存有多少组
        int sum = 0;
        int cur1 = 0;
        int cur2 = 1;
        int cur3 = 2;
        for (int i = 0; i < nums.length - 2; i++) {
            for (int j = i + 1; j < nums.length - 1; j++) {
                for (int k = j + 1; k < nums.length; k++) {
                    if (nums[i] + nums[j] > nums[k]) {
                        sum++;
                    } else {
                        break;
                    }
                }
            }
        }
        return sum;

    }

    public int triangleNumber2(int[] nums) {
        Arrays.sort(nums);
        int max = nums.length - 1;
        int sum = 0;
        while (max >= 2) {
            int left = 0;
            int right = max - 1;
            while (left < right) {
                if (nums[left] + nums[right] > nums[max]) {
                    sum += right - left;
                    right--;
                } else {
                    left++;
                }
            }
            max--;
        }
        return sum;
    }

    public int[] twoSum1(int[] nums, int target) {
        int[] arr = new int[2];
        int num1 = 0;
        int num2 = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            num1 = nums[i];
            for (int j = 0; j < nums.length; j++) {
                num2 = nums[j];
                if ((num1 + num2) == target) {
                    arr[0] = num1;
                    arr[1] = num2;
                    return arr;
                }
                if ((num1 + num2) > target) break;
            }
        }
        return arr;
    }

    public int[] twoSum(int[] nums, int target) {
        int[] arr = new int[2];
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            if (nums[left] + nums[right] == target) {
                arr[0] = nums[left];
                arr[1] = nums[right];
                return arr;
            } else if (nums[left] + nums[right] > target) {
                right--;
            } else {
                left++;
            }
        }
        return arr;
    }

    public int iceBreakingGame(int num, int target) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            list.add(i);
        }
        int cur = 0;
        int call = 0;
        while (list.size() != 1) {
            call++;
            if (call == target) {
                list.remove(cur);
                call = 0;
                if (cur == list.size()) cur = 0;
                continue;
            }
            cur++;
            if (cur == list.size()) cur = 0;
        }
        return list.get(0);
    }

    public List<List<Integer>> threeSum(int[] nums) {
        Set<List<Integer>> set = new HashSet<>();
        //排序
        Arrays.sort(nums);
        for (int i = 0; i < nums.length - 2; i++) {
            if (nums[i] > 0) break;
            for (int j = i + 1; j < nums.length - 1; j++) {
                if (nums[i] + nums[j] > 0) break;
                for (int k = j + 1; k < nums.length; k++) {
                    if (nums[i] + nums[j] + nums[k] > 0) {
                        break;
                    } else if (nums[i] + nums[j] + nums[k] == 0) {
                        List<Integer> list = new ArrayList<>();
                        list.add(nums[i]);
                        list.add(nums[j]);
                        list.add(nums[k]);
                        set.add(list);
                    }

                }
            }
        }

        List<List<Integer>> arr = new ArrayList<>();
        for (
                List<Integer> list : set
        ) {
            arr.add(list);
        }
        return arr;
    }

    public List<List<Integer>> threeSum2(int[] nums) {
        Arrays.sort(nums);
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < nums.length - 2; i++) {
            if (i >= 1) {
                if (nums[i] == nums[i - 1]) continue;
            }
            int left = i + 1;
            int right = nums.length - 1;
            if (nums[i] + nums[left] > 0) break;
            while (left < right) {
                if (nums[left] + nums[right] < -nums[i]) {
                    left++;
                    if (left < right && nums[left] == nums[left - 1]) {
                        left++;
                    }
                } else if (nums[left] + nums[right] > -nums[i]) {
                    right--;
                    if (left < right && nums[right] == nums[right + 1]) {
                        right--;
                    }
                } else {
                    List<Integer> minList = new ArrayList<>();
                    minList.add(nums[i]);
                    minList.add(nums[left]);
                    minList.add(nums[right]);
                    list.add(minList);
                    right--;
                    if (left < right && nums[right] == nums[right + 1]) {
                        right--;
                    }
                    left++;
                    if (left < right && nums[left] == nums[left - 1]) {
                        left++;
                    }
                }
            }
        }
        return list;
    }

    public int lengthOfLongestSubstring1(String s) {
        Map<Character, Integer> map = new HashMap<>();
        char[] arr = s.toCharArray();
        int max = 0;
        int len = arr.length;
        for (int left = 0, right = 0; right < len; right++) {
            int count = map.get(arr[right]) == null ? 0 : map.get(arr[right]);
            map.put(arr[right], count + 1);
            while (map.get(arr[right]) > 1) {
                map.put(arr[left], map.get(arr[left]) - 1);
                left++;
            }
            max = Math.max(max, right - left + 1);
        }
        return max;

    }

    public int lengthOfLongestSubstring(String s) {
        Map<Character, Integer> map = new HashMap<>();
        char[] arr = s.toCharArray();
        int max = 0;
        int len = arr.length;
        int[] hash = new int[256];
        for (int left = 0, right = 0; right < len; right++) {
            hash[arr[right]]++;
            while (hash[arr[right]] > 1) {
                hash[arr[left]]--;
                left++;
            }
            max = Math.max(max, right - left + 1);
        }
        return max;

    }


    public List<List<Integer>> fourSum(int[] nums, int target) {
        List<List<Integer>> list = new ArrayList<>();
        //排序
        Arrays.sort(nums);
        int len = nums.length;
        for (int i = 0; i < len - 3; i++) {
            if (i > 0) {
                if (nums[i] == nums[i - 1]) continue;
            }
            //转换为三个数字之和
            int target1 = target - nums[i];
            for (int j = i + 1; j < len - 2; j++) {
                if (j > i + 1) {
                    if (nums[j] == nums[j - 1]) continue;
                }
                int target2 = target1 - nums[j];
                int left = j + 1;
                int right = len - 1;
                while (left < right) {
                    if (nums[left] + nums[right] > target2) {
                        right--;
                        while (left < right && nums[right] == nums[right + 1]) right--;
                    } else if (nums[left] + nums[right] < target2) {
                        left++;
                        while (left < right && nums[left] == nums[left - 1]) left++;
                    } else {
                        list.add(Arrays.asList(nums[i], nums[j], nums[left], nums[right]));
                        left++;
                        while (left < right && nums[left] == nums[left - 1]) left++;
                        right--;
                        while (left < right && nums[right] == nums[right + 1]) right--;
                    }
                }

            }
        }
        return list;
    }

    public int minOperations(int[] nums, int x) {
        int len = nums.length;
        int max = 0;
        int sum = 0;
        int sumLen = 0;
        int target = 0;
        for (int i = 0; i < nums.length; i++) {
            target += nums[i];
        }
        target -= x;
        for (int left = 0, right = 0; right < len; right++) {
            sum += nums[right];
            sumLen++;
            while (sum > target) {
                sum -= nums[left];
                left++;
                sumLen--;
            }
            if (sum == target) max = Math.max(max, sumLen);
        }
        return max == 0 ? -1 : max;
    }

    public boolean isUnique(String astr) {
        char[] arr = astr.toCharArray();
        int[] hash = new int[256];
        for (int i = 0; i < arr.length; i++) {
            hash[arr[i]]++;
        }
        for (int i = 0; i < hash.length; i++) {
            if (hash[i] > 1) return false;
        }
        return true;
    }


    public static int mySqrt(int x) {
        int left = 0;
        int right = x;
        while (left < right) {
            long mid = left + (right - left + 1) / 2;
            if (mid * mid <= x) left = (int) mid;
            else right = (int) (mid - 1);
        }
        return left;
    }

//    public static void main(String[] args) {
//        int a = mySqrt(21748347);
//        System.out.println(a);
//    }
//    public int totalFruit(int[] fruits) {
//        HashMap<Integer,Integer> map=new HashMap<>();
//        int len=fruits.length;
//        int sum=0;
//        int max=0;
//        for (int left = 0, right = 0;right<len;right++ ){
//            sum++;
//            Integer count = map.getOrDefault(fruits[right], 0);
//            map.put(fruits[right],count+1);
//            while (map.size()>2){
//                sum--;
//                Integer fruit = map.get(fruits[left]);
//                map.put(fruits[left],fruit-1);
//                if(map.get(fruits[left])==0){
//                    map.remove(fruits[left]);
//                }
//                left++;
//            }
//            max=Math.max(max,sum);
//        }
//        return  max;
//    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n=in.nextInt();
        int m=in.nextInt();
        int q=in.nextInt();
        int[][] arr=new int[n+1][m+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                arr[i][j]=in.nextInt();
            }
        }
        long[][] dp=new long[n+1][m+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+arr[i][j];
            }
        }
        while(q>0){
            q--;
            int x1=in.nextInt();
            int y1=in.nextInt();
            int x2=in.nextInt();
            int y2=in.nextInt();
            long area=dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1];
            System.out.println(area);

        }
    }
}
